package com.cloud.quickcore.admin.entity;

import com.cloud.quickcore.admin.enums.ActiveTypeEnum;
import com.cloud.quickcore.admin.enums.FrozenTypenEnum;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 用户信息表
 *
 * @author NiJo_H
 * @version 1.0
 * @date 2019/7/27 21:58
 */
@Data
@Entity
@Table(name = "sys_user")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public class SysUser {

    @Id
    @GeneratedValue(generator = "system-uuid")
    @Column(name = "id", updatable = false, length = 32)
    private String id;

    /**
     * 昵称
     */
    @Column(name = "name", length = 30, nullable = false)
    private String name;

    /**
     * 登陆用户名
     */
    @Column(name = "username", length = 30, nullable = false)
    private String username;

    /**
     * 密码
     */
    @Column(name = "password", length = 100, nullable = false)
    private String password;

    /**
     * 邮箱
     */
    @Column(name = "email", length = 50, nullable = false)
    private String email;

    /**
     * 盐
     */
    @Column(name = "salt", length = 50, nullable = false)
    private String salt;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "create_at")
    private LocalDateTime createAt;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "update_at")
    private LocalDateTime updateAt;

    /**
     * 冻结标志 false:未冻结
     */
    @Column(name = "frozen")
    private FrozenTypenEnum frozen = FrozenTypenEnum.NO_FROZEN;

    /**
     * 删除标志
     */
    @Column(name = "is_delete")
    private boolean isDelete = false;

    /**
     * 激活标志 false:未激活
     */
    @Column(name = "active")
    private ActiveTypeEnum active = ActiveTypeEnum.NOT_ACTIVE;

    //@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH}, fetch = FetchType.LAZY)
    //@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH}, fetch = FetchType.LAZY)
    //@JoinTable(name = "sys_user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = {@JoinColumn(name = "role_id")})
    @ManyToMany
    @JoinTable(name = "sys_user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<SysRole> roles;
}
